home *** CD-ROM | disk | FTP | other *** search
/ Merciful 1 / Merciful - Disc 1.iso / software / b / blitz_blanker / blitzblankerv2.05a.dms / BlitzBlank_2.50 / Developer / Modulesources / BB.Lines.c < prev    next >
C/C++ Source or Header  |  1995-03-01  |  5KB  |  250 lines

  1. #define __USE_SYSBASE 1
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <math.h>
  7. #include <dos.h>
  8. #include <dos/dos.h>
  9. #include <exec/memory.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <intuition/screens.h>
  12. #include <intuition/intuition.h>
  13. #include <proto/exec.h>
  14. #include <proto/intuition.h>
  15. #include <proto/graphics.h>
  16. #include <pragmas/blitzblank_pragmas.h>
  17.  
  18. #include <BlitzBlank.h>
  19.  
  20. struct Library *BlitzBlankBase;
  21. static const char version[]="$VER: BB.Lines 2.50 (25.12.94)";
  22.  
  23. char *text[]={"\33c\33uLines\33n\n\nModule for BlitzBlank\n\nCopyright 1994\nby\nThomas Börkel",
  24.               "_Lines:" };
  25.  
  26. struct BB_Object object[]={ {&object[1],BB_VGroup,0,0,0,NULL,NULL},
  27.                             {&object[2],BB_Slider,5,200,50,NULL,NULL},
  28.                             {NULL      ,BB_VGroup_End,0,0,0,NULL,NULL} };
  29.  
  30. struct line
  31. {
  32.   int x1;
  33.   int y1;
  34.   int x2;
  35.   int y2;
  36.   int c;
  37. };
  38.  
  39.  
  40. struct BB_Message message;
  41. struct BB_Screeninfo *screeninfo;
  42. struct RastPort *rp;
  43. struct line *li;
  44. int dx1,dy1,dx2,dy2;
  45.  
  46.  
  47. int sgn (long a)
  48. {
  49.   if (a<0)
  50.     return (-1);
  51.   if (a>0)
  52.     return (1);
  53.   return (0);
  54. }
  55.  
  56.  
  57. void check (int i)
  58. {
  59.   if (li[i].x1>screeninfo->width-1 || li[i].x1<0)
  60.   {
  61.     dx1=-dx1;
  62.     li[i].x1+=2*dx1;
  63.   }
  64.   if (li[i].y1>screeninfo->height-1 || li[i].y1<0)
  65.   {
  66.     dy1=-dy1;
  67.     li[i].y1+=2*dy1;
  68.   }
  69.   if (li[i].x2>screeninfo->width-1 || li[i].x2<0)
  70.   {
  71.     dx2=-dx2;
  72.     li[i].x2+=2*dx2;
  73.   }
  74.   if (li[i].y2>screeninfo->height-1 || li[i].y2<0)
  75.   {
  76.     dy2=-dy2;
  77.     li[i].y2+=2*dy2;
  78.   }
  79.   return;
  80. }
  81.  
  82.  
  83. void blank (void)
  84. {
  85.   int i,colors,al,w=3,s=1,co=1,ch,stop=FALSE,v;
  86.   struct ViewPort *vp;
  87.   struct DateStamp ds;
  88.  
  89.   al=object[1].set;
  90.  
  91.   if (!(li=calloc (al+1,sizeof (struct line)))) return;
  92.  
  93.   colors=1<<screeninfo->depth;
  94.   rp=&screeninfo->bbscreen->RastPort;
  95.   vp=&screeninfo->bbscreen->ViewPort;
  96.  
  97.   DateStamp (&ds);
  98.   srand48 (ds.ds_Minute*60+ds.ds_Tick);
  99.  
  100.   SetRGB4 (vp,0,0,0,0);
  101.   SetRGB4 (vp,1,15,0,0);
  102.   if (colors>2)
  103.   {
  104.     SetRGB4 (vp,2,0,0,15);
  105.     SetRGB4 (vp,3,0,15,0);
  106.     if (colors>4)
  107.     {
  108.       SetRGB4 (vp,4,0,5,0);
  109.       SetRGB4 (vp,5,15,3,8);
  110.       SetRGB4 (vp,6,15,5,15);
  111.       SetRGB4 (vp,7,5,15,8);
  112.       if (colors>8)
  113.       {
  114.         SetRGB4 (vp,8,10,5,0);
  115.         SetRGB4 (vp,9,0,15,5);
  116.         SetRGB4 (vp,10,15,7,15);
  117.         SetRGB4 (vp,11,0,7,15);
  118.         SetRGB4 (vp,12,8,15,3);
  119.         SetRGB4 (vp,13,15,10,5);
  120.         SetRGB4 (vp,14,7,0,15);
  121.         SetRGB4 (vp,15,3,8,15);
  122.         if (colors>16)
  123.           for (i=16;i<colors;i++)
  124.             SetRGB4 (vp,i,(long) (drand48 ()*13+3),(long) (drand48 ()*13+3),(long) (drand48 ()*13+3));
  125.       }
  126.     }
  127.   }
  128.  
  129.   ch=al/colors;
  130.   if (ch==0)
  131.     ch=1;
  132.  
  133.   dx1=drand48 ()*w+s;
  134.   dy1=drand48 ()*w+s;
  135.   dx2=drand48 ()*w+s;
  136.   dy2=drand48 ()*w+s;
  137.  
  138.   li[0].x1=drand48 ()*screeninfo->width;
  139.   li[0].y1=drand48 ()*screeninfo->height;
  140.   li[0].x2=drand48 ()*screeninfo->width;
  141.   li[0].y2=drand48 ()*screeninfo->height;
  142.  
  143.   ScreenToFront (screeninfo->bbscreen);
  144.  
  145.   if (!CheckSignal (SIGBREAKF_CTRL_C))
  146.   {
  147.     BBL_ModuleRunning ();
  148.  
  149.     for (i=1;i<al;i++)
  150.     {
  151.       li[i].x1=li[i-1].x1+dx1;
  152.       li[i].y1=li[i-1].y1+dy1;
  153.       li[i].x2=li[i-1].x2+dx2;
  154.       li[i].y2=li[i-1].y2+dy2;
  155.       check (i);
  156.       if (i%ch==0)
  157.       {
  158.         co++;
  159.         if (co>colors-1)
  160.           co=1;
  161.       }
  162.       SetAPen (rp,co);
  163.       Move (rp,li[i].x1,li[i].y1);
  164.       Draw (rp,li[i].x2,li[i].y2);
  165.       if (CheckSignal (SIGBREAKF_CTRL_C))
  166.       {
  167.         i=al-1;
  168.         stop=TRUE;
  169.       }
  170.     }
  171.  
  172.     if (!stop && !CheckSignal (SIGBREAKF_CTRL_C))
  173.     {
  174.       i=0;
  175.       v=al-1;
  176.       do
  177.       {
  178.         SetAPen (rp,0);
  179.         Move (rp,li[i].x1,li[i].y1);
  180.         Draw (rp,li[i].x2,li[i].y2);
  181.         li[i].x1=li[v].x1+dx1;
  182.         li[i].y1=li[v].y1+dy1;
  183.         li[i].x2=li[v].x2+dx2;
  184.         li[i].y2=li[v].y2+dy2;
  185.         check (i);
  186.         if (i%ch==0)
  187.         {
  188.           co++;
  189.           if (co>colors-1)
  190.             co=1;
  191.         }
  192.         SetAPen (rp,co);
  193.         Move (rp,li[i].x1,li[i].y1);
  194.         Draw (rp,li[i].x2,li[i].y2);
  195.         i++;
  196.         if (i>al-1)
  197.         {
  198.           i=0;
  199.           dx1=sgn(dx1)*(drand48 ()*w+s);
  200.           dy1=sgn(dy1)*(drand48 ()*w+s);
  201.           dx2=sgn(dx2)*(drand48 ()*w+s);
  202.           dy2=sgn(dy2)*(drand48 ()*w+s);
  203.         }
  204.         v++;
  205.         if (v>al-1)
  206.           v=0;
  207.       } while (!CheckSignal (SIGBREAKF_CTRL_C));
  208.     }
  209.   }
  210.   return;
  211. }
  212.  
  213.  
  214. void main(int argc,char **argv)
  215. {
  216.  
  217.   if (!(BlitzBlankBase=OpenLibrary ("blitzblank.library",BLITZBLANKLIB_VER)))
  218.     exit (0);
  219.  
  220.   message.flags=BBF_Screenmode|BBF_Colors;
  221.   message.first=&object[0];
  222.   screeninfo->maxdepth=4;
  223.  
  224.   if (strcmp (argv[1],"BLANK")==0)
  225.   {
  226.     StrToLong (argv[3],(long *) &screeninfo);
  227.     BBL_SendMessage (&message,argv[2]);
  228.     if (screeninfo->bbscreen)
  229.       blank ();
  230.     BBL_BlankDone ();
  231.   }
  232.   else
  233.   {
  234.     message.infotext=BBL_GetString (270,text[0]);
  235.     object[1].label=BBL_GetString (271,text[1]);
  236.     if (strcmp (argv[1],"CONFIG")==0)
  237.     {
  238.       BBL_SendMessage (&message,argv[2]);
  239.     }
  240.     else
  241.     {
  242.       message.first=NULL;
  243.       BBL_SendMessage (&message,argv[2]);
  244.     }
  245.   }
  246.   CloseLibrary (BlitzBlankBase);
  247.   exit (0);
  248. }
  249.  
  250.